import { createSlice, PayloadAction } from '@reduxjs/toolkit'

const initialState = {
	username: '',
	nickname: '',
	avator: ''
}

const userSlice = createSlice({
	name: 'user',
	initialState,
	reducers: {
		loginSuccess(state, action: PayloadAction<typeof initialState>) {
			state.username = action.payload.username
			state.nickname = action.payload.nickname
			state.avator = action.payload.avator
		},
		setAvator(state, action: PayloadAction<string>) {
			state.avator = action.payload
		}
	}
})

export const { loginSuccess, setAvator } = userSlice.actions
export default userSlice.reducer